package com.ss.android.article.base.feature.feed.activity;

import android.content.Context;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;

public class NewInfoLayout extends LinearLayout {
    final class a implements Runnable {
        private final NewInfoLayout a;

        a(NewInfoLayout arg1, byte arg2) {
            this(arg1);
        }

        private a(NewInfoLayout arg1) {
            this.a = arg1;

        }

        public final void run() {
            Rect v0 = new Rect();
            this.a.newInfoLayoutDislike.getHitRect(v0);
            v0.bottom += this.a.mContext.getResources().getDimensionPixelOffset(R.dimen.er);
            v0.left -= this.a.mContext.getResources().getDimensionPixelOffset(R.dimen.eq);
            v0.right += this.a.mContext.getResources().getDimensionPixelOffset(R.dimen.eq);
            v0.top -= this.a.mContext.getResources().getDimensionPixelOffset(R.dimen.er);
            this.a.newInfoLayoutImageContainer.setTouchDelegate(new TouchDelegate(v0, this.a.newInfoLayoutDislike));
        }
    }

    Context mContext;
    LinearLayout newInfoLayoutImageContainer;
    ImageView newInfoLayoutDislike;
    private TextView newInfoLayoutName;
    private TextView newInfoLayoutAuthInfo;
    private TextView newInfoLayoutShitici;
    private TextView newInfoLayoutLabel;
    private TextView newInfoLayoutComment;
    private TextView mNewInfoLayoutDigg;
    private TextView newInfoLayoutReadedNum;
    private TextView newInfoLayoutTime;
    private TextView newInfoLayoutLocation;
    private View authInfoDivider;
    private ImageView shiticiDivider;
    private View commentDivider;
    private View diggDivider;
    private View readedNumDivider;
    private View timeDivider;
    private View locationDivider;
    private NightModeAsyncImageView newInfoLayoutVTT;
    private TextView newInfoLayoutFakePgcImg;
    private NightModeAsyncImageView mNewInfoLayoutHeadImage;
    private boolean isNightMode;
    private ColorFilter nightModeColorFilter;
    private InfoLayout.Info mInfo;
    private a z;

    public NewInfoLayout(Context arg2) {
        this(arg2, null);
    }

    public NewInfoLayout(Context arg2, AttributeSet arg3) {
        this(arg2, arg3, 0);
    }

    public NewInfoLayout(Context context, AttributeSet arg4, int arg5) {
        super(context, arg4, arg5);
        this.mContext = context;
        NewInfoLayout.inflate(this.getContext(), R.layout.new_info_layout, ((ViewGroup) this));
        this.setGravity(16);
        AppData.getInstance();
        this.isNightMode = AppData.isNightMode();
        this.newInfoLayoutFakePgcImg = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_fake_pgc_img);
        this.newInfoLayoutName = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_name);
        this.newInfoLayoutAuthInfo = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_auth_info);
        this.newInfoLayoutShitici = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_shitici);
        this.newInfoLayoutLabel = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_label);
        this.newInfoLayoutComment = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_comment);
        this.mNewInfoLayoutDigg = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_digg);
        this.newInfoLayoutReadedNum = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_readed_num);
        this.newInfoLayoutTime = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_time);
        this.newInfoLayoutLocation = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_location);
        this.mNewInfoLayoutHeadImage = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_head_img);
        this.newInfoLayoutDislike = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_dislike);
        this.newInfoLayoutVTT = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_vtt);
        this.newInfoLayoutImageContainer = this.findViewById(com.ss.android.article.browser.R.id.new_info_layout_img_container);
        this.z = new a(this, (byte) 0);
        this.newInfoLayoutImageContainer.post(this.z);
        this.authInfoDivider = this.findViewById(com.ss.android.article.browser.R.id.auth_info_divider);
        this.shiticiDivider = this.findViewById(com.ss.android.article.browser.R.id.shitici_divider);
        this.commentDivider = this.findViewById(com.ss.android.article.browser.R.id.comment_divider);
        this.diggDivider = this.findViewById(com.ss.android.article.browser.R.id.digg_divider);
        this.readedNumDivider = this.findViewById(com.ss.android.article.browser.R.id.readed_num_divider);
        this.timeDivider = this.findViewById(com.ss.android.article.browser.R.id.time_divider);
        this.locationDivider = this.findViewById(com.ss.android.article.browser.R.id.location_divider);
        this.nightModeColorFilter = TTUtils.getNightModeColorFilter();
        this.newInfoLayoutName.getPaint().setFakeBoldText(true);
    }

    private static void toggleView(View view, boolean visible) {
        if (visible) {
            view.setVisibility(View.VISIBLE);
        } else {
            view.setVisibility(View.GONE);
        }
    }

    public final void adaptNightMode() {
        if (this.isNightMode != AppData.isNightMode()) {
            this.isNightMode = AppData.isNightMode();
            ColorFilter colorFilter = this.isNightMode ? this.nightModeColorFilter : null;
            this.mNewInfoLayoutHeadImage.setColorFilter(colorFilter);
            this.newInfoLayoutDislike.setImageDrawable(ContextCompat.getDrawable(this.getContext(), R.drawable.dislikeicon_textpage));
            this.newInfoLayoutName.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi2));
            this.newInfoLayoutAuthInfo.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi2));
            this.newInfoLayoutShitici.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi2));
            this.newInfoLayoutComment.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi3));
            this.mNewInfoLayoutDigg.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi3));
            this.newInfoLayoutTime.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi3));
            this.newInfoLayoutLocation.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi3));
            this.newInfoLayoutReadedNum.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi3));
        }
    }

    public final void a(InfoLayout.Info info) {
        boolean v0;
        int v7 = R.drawable.all_newv;
        float v6 = 3f;
        boolean v1 = true;
        int v5 = View.GONE;
        if (info == null) {
            Logger.throwException("info is null !!!");
        } else {
            info.c();
            this.mInfo = info;
            this.adaptNightMode();
            if (!this.mInfo.y) {
                this.mNewInfoLayoutHeadImage.setVisibility(v5);
                this.newInfoLayoutFakePgcImg.setVisibility(v5);
            } else if (!android.support.design.a.isTextEmpty(this.mInfo.avatarUrl)) {
                this.newInfoLayoutFakePgcImg.setVisibility(v5);
                this.mNewInfoLayoutHeadImage.setVisibility(View.VISIBLE);
                this.mNewInfoLayoutHeadImage.setUrl(this.mInfo.avatarUrl);
                if (this.isNightMode) {
                    this.mNewInfoLayoutHeadImage.setColorFilter(this.nightModeColorFilter);
                }
            } else if (!android.support.design.a.isTextEmpty(this.mInfo.d)) {
                this.mNewInfoLayoutHeadImage.setVisibility(v5);
                this.newInfoLayoutFakePgcImg.setVisibility(View.VISIBLE);
                this.newInfoLayoutFakePgcImg.setText(this.mInfo.d.substring(0, 1));
                this.newInfoLayoutFakePgcImg.setTextSize(1, 18f);
                this.newInfoLayoutFakePgcImg.setTextColor(ContextCompat.getColor(this.getContext(), R.color.ssxinzi7));
                this.newInfoLayoutFakePgcImg.setBackgroundResource(com.ss.android.article.browser.R.drawable.circle_solid_mian7);
                this.newInfoLayoutFakePgcImg.setGravity(17);
                this.newInfoLayoutFakePgcImg.getPaint().setFakeBoldText(true);
                android.support.design.a.b(this.newInfoLayoutFakePgcImg, this.mInfo.i);
            }

            if (!this.mInfo.q || (android.support.design.a.isTextEmpty(this.mInfo.d))) {
                this.newInfoLayoutName.setVisibility(v5);
                v0 = false;
            } else {
                this.newInfoLayoutName.setVisibility(View.VISIBLE);
                this.newInfoLayoutName.setText(this.mInfo.d);
                v0 = true;
            }

            if (!this.mInfo.C || (android.support.design.a.isTextEmpty(this.mInfo.l))) {
                if ((this.mInfo.B) && (v0) && this.newInfoLayoutName.getVisibility() == View.VISIBLE) {
                    AppData.isNightMode();
                    this.newInfoLayoutName.setCompoundDrawablesWithIntrinsicBounds(0, 0, v7, 0);
                    this.newInfoLayoutName.setCompoundDrawablePadding(((int) UIUtils.dp2px(this.getContext(), v6)));
                }

                this.authInfoDivider.setVisibility(v5);
                this.newInfoLayoutAuthInfo.setVisibility(v5);
            } else {
                NewInfoLayout.toggleView(this.authInfoDivider, v0);
                this.newInfoLayoutAuthInfo.setVisibility(View.VISIBLE);
                this.newInfoLayoutAuthInfo.setText(this.mInfo.l);
                if (this.mInfo.B) {
                    TextView v0_1 = this.newInfoLayoutAuthInfo;
                    AppData.isNightMode();
                    v0_1.setCompoundDrawablesWithIntrinsicBounds(0, 0, v7, 0);
                    this.newInfoLayoutAuthInfo.setCompoundDrawablePadding(((int) UIUtils.dp2px(this.getContext(), v6)));
                    if (this.newInfoLayoutName.getVisibility() == View.VISIBLE) {
                        this.newInfoLayoutName.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
                        this.newInfoLayoutName.setCompoundDrawablePadding(0);
                    }
                }

                v0 = true;
            }

            if (!this.mInfo.D || (android.support.design.a.isTextEmpty(this.mInfo.m))) {
                this.shiticiDivider.setVisibility(v5);
                this.newInfoLayoutShitici.setVisibility(v5);
            } else {
                NewInfoLayout.toggleView(this.shiticiDivider, v0);
                this.newInfoLayoutShitici.setVisibility(View.VISIBLE);
                this.newInfoLayoutShitici.setText(this.mInfo.m);
            }

            if (!this.mInfo.v || (android.support.design.a.isTextEmpty(this.mInfo.c))) {
                this.newInfoLayoutLabel.setVisibility(v5);
                v0 = false;
            } else {
                this.newInfoLayoutLabel.setVisibility(View.VISIBLE);
                int v0_2 = android.support.design.a.b(this.getContext(), this.mInfo.labelStyle);
                if (this.mInfo.labelStyle == 3) {
                    AppData.getInstance();
                    AppData.isNightMode();
                    v0_2 = ContextCompat.getColor(this.mContext, R.color.update_comment_more_text_selector);
                }

                this.newInfoLayoutLabel.setTextColor(v0_2);
                this.newInfoLayoutLabel.setText(this.mInfo.c);
                v0 = true;
            }

            if (!this.mInfo.r || (android.support.design.a.isTextEmpty(this.mInfo.e))) {
                this.commentDivider.setVisibility(v5);
                this.newInfoLayoutComment.setVisibility(v5);
            } else {
                NewInfoLayout.toggleView(this.commentDivider, v0);
                this.newInfoLayoutComment.setVisibility(View.VISIBLE);
                this.newInfoLayoutComment.setText(this.mInfo.e);
                v0 = true;
            }

            if (!this.mInfo.A || (android.support.design.a.isTextEmpty(this.mInfo.k))) {
                this.diggDivider.setVisibility(v5);
                this.mNewInfoLayoutDigg.setVisibility(v5);
            } else {
                NewInfoLayout.toggleView(this.diggDivider, v0);
                this.mNewInfoLayoutDigg.setVisibility(View.VISIBLE);
                this.mNewInfoLayoutDigg.setText(this.mInfo.k);
                v0 = true;
            }

            if (!this.mInfo.E || (android.support.design.a.isTextEmpty(this.mInfo.n))) {
                this.readedNumDivider.setVisibility(v5);
                this.newInfoLayoutReadedNum.setVisibility(v5);
            } else {
                NewInfoLayout.toggleView(this.readedNumDivider, v0);
                this.newInfoLayoutReadedNum.setVisibility(View.VISIBLE);
                this.newInfoLayoutReadedNum.setText(this.mInfo.n);
                v0 = true;
            }

            if (!this.mInfo.s || (android.support.design.a.isTextEmpty(this.mInfo.f))) {
                this.timeDivider.setVisibility(v5);
                this.newInfoLayoutTime.setVisibility(v5);
                v1 = v0;
            } else {
                NewInfoLayout.toggleView(this.timeDivider, v0);
                this.newInfoLayoutTime.setVisibility(View.VISIBLE);
                this.newInfoLayoutTime.setText(this.mInfo.f);
            }

            if (!this.mInfo.F || (android.support.design.a.isTextEmpty(this.mInfo.o))) {
                this.locationDivider.setVisibility(v5);
                this.newInfoLayoutLocation.setVisibility(v5);
            } else {
                NewInfoLayout.toggleView(this.locationDivider, v1);
                this.newInfoLayoutLocation.setVisibility(View.VISIBLE);
                this.newInfoLayoutLocation.setText(this.mInfo.o);
            }

            if ((this.mInfo.w) || (this.mInfo.x)) {
                this.newInfoLayoutDislike.setVisibility(View.VISIBLE);
            } else {
                this.newInfoLayoutDislike.setVisibility(v5);
            }

            if (!this.mInfo.G) {
                return;
            }

            if (android.support.design.a.isTextEmpty(this.mInfo.tinyTouTiaoUrl)) {
                return;
            }

            this.newInfoLayoutVTT.setVisibility(View.VISIBLE);
            this.newInfoLayoutVTT.setUrl(this.mInfo.tinyTouTiaoUrl);
            if (!this.isNightMode) {
                return;
            }

            this.newInfoLayoutVTT.setColorFilter(this.nightModeColorFilter);
        }
    }

    public final void b() {
        if (this.mInfo != null) {
            if (this.mNewInfoLayoutHeadImage.getVisibility() == View.VISIBLE) {
                this.mNewInfoLayoutHeadImage.setVisibility(View.GONE);
                this.mNewInfoLayoutHeadImage.setColorFilter(null);
            }

            if (this.newInfoLayoutVTT.getVisibility() == View.VISIBLE) {
                this.newInfoLayoutVTT.setVisibility(View.GONE);
                this.newInfoLayoutVTT.setColorFilter(null);
            }

            this.newInfoLayoutName.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            this.newInfoLayoutAuthInfo.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            this.newInfoLayoutDislike.setOnClickListener(null);
            this.mNewInfoLayoutHeadImage.setOnClickListener(null);
            this.newInfoLayoutName.setOnClickListener(null);
            this.mInfo.a();
            this.mInfo = null;
            this.z = null;
        }
    }

    public void setDislikeOnClickListener(View.OnClickListener arg2) {
        this.newInfoLayoutDislike.setOnClickListener(arg2);
    }

    public void setSourceOnClickListener(View.OnClickListener arg2) {
        this.mNewInfoLayoutHeadImage.setOnClickListener(arg2);
        this.newInfoLayoutName.setOnClickListener(arg2);
    }
}

